package com.neuedu.web.dao;

import com.neuedu.web.common.BaseDao;
import com.neuedu.web.po.MenuPO;
import com.neuedu.web.po.MenuPO;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * @author 金山
 * 项目：jdbc-dao
 * site: https://blog.fulfill.com.cn
 * 描述  Role 表的数据访问对象
 * @data  2024年11月21日13:38:03
 */
public class MenuDao extends BaseDao<MenuPO> {



    public List<MenuPO> selectAll(  String sql, Object... params) throws NoSuchFieldException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        return super.selectAll(MenuPO.class , sql,params);
    }
    public List<MenuPO> selectPage( int current, int size, String sql, Object... params) throws NoSuchFieldException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        return super.selectPage(MenuPO.class , current ,size,sql,params);
    }



    public MenuPO selectById(long id) throws NoSuchFieldException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {


        String sql = "select * from ums_menu where menu_id= ?";
        return super.selectOne(MenuPO.class,sql,id);

    }



    public int insert(MenuPO menu) {
        String sql = "INSERT INTO `his`.`ums_menu` (   `menu_name`,url,path,level,parent_id) VALUES(  ?,?,?,?,?)  ";
        int count = super.update(sql,
                menu.getMenuName(),
                menu.getUrl(),
                menu.getPath(),
                menu.getLevel(),
                menu.getParentId()
        );
        return count;
    }

    public int update(MenuPO menu) {
        StringBuffer sql = new StringBuffer();

        sql.append(" update 					");
        sql.append("   `ums_menu` 			");
        sql.append(" set			");
        sql.append("   `menu_name` = ?,			");
        sql.append("   `url` = ?,			");
        sql.append("   `path` = ?,			");
        sql.append("   `level` = ?,			");
        sql.append("   `parent_id` = ?		");


        sql.append(" where `menu_id` =  ?			");


        int count = super.update(sql.toString(),
                menu.getMenuName(),
                menu.getUrl(),
                menu.getPath(),
                menu.getLevel(),
                menu.getParentId(),

                menu.getMenuId()
        );

        return count;

    }

    /**
     * 通用的方法
     *
     * @return
     */

    public int delete(long id) {
        StringBuffer sql = new StringBuffer();

        sql.append(" delete from ums_menu where menu_id = ?");

        int count = super.update(sql.toString(),   id        );

        return count;
    }

}
